﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Subtle.Domain.Models;

namespace Subtle.Areas.Administration.ViewModels
{
	/// <summary>
	/// Edit Post View Model
	/// </summary>
	public class EditPostViewModel
	{
		public int ID { get; set; }

		[Required]
		public string Title { get; set; }

		[Required]
		public string Body { get; set; }

		[Required]
		[Display(Name = "Tags")]
		public string Tags { get; set; }

		[Required]
		[Display(Name = "Category")]
		public string CategoryDescription { get; set; }

		public bool Active { get; set; }

		public DateTime PublishDate { get; set; }

		/// <summary>
		/// Get Post
		/// </summary>
		/// <returns></returns>
		public Post GetPost()
		{
			Post post = new Post();
			AutoMapper.Mapper.Map<EditPostViewModel, Post>(this, post);

			post.Category.Description = CategoryDescription;

			return post;
		}

		/// <summary>
		/// Get Post
		/// </summary>
		/// <param name="post"></param>
		/// <returns></returns>
		public static EditPostViewModel GetModel(Post post)
		{
			EditPostViewModel editPostViewModel = new EditPostViewModel();
			if (post != null)
			{
				editPostViewModel = AutoMapper.Mapper.Map<Post, EditPostViewModel>(post, editPostViewModel);
			}
			return editPostViewModel;
		}
	}
}